package com.topisv.tms.repository.stock.instorage;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.stock.instorage.InstorageUpTaskItem;

/**
 * 上架明细
 *  Date          Author       Version       Description
 * ----------------------------------------------------------
 *  2015-4-14      CC            1.0           Create
 */
public interface InstorageUpTaskItemDao extends PagingAndSortingRepository<InstorageUpTaskItem, Long>, JpaSpecificationExecutor<InstorageUpTaskItem> {
	
	List<InstorageUpTaskItem> findByUpTaskCode(String taskCode);
	
	@Query("select t from InstorageUpTaskItem t where t.upTaskCode = ?1 and skuCode = ?2 and boxCode = ?3 and stockCode = ?4 and t.errorFlag =?5")
	InstorageUpTaskItem findBy(String upTaskCode,String skuCode,String boxCode,String stockCode,String errorFlag);
	
	@Query("select new map(t.skuCode,sum(t.num) as num) from InstorageUpTaskItem t where t.upTaskCode = ?1 and skuCode = ?2 and errorFlag = ?3 ")
	Map<String, Object> findByNew(String upTaskCode,String skuCode,String errorFlag);
	
}
